% FIGURE HANDLING MACROS (written by P. Galko,  Aug 13/90)
% � P. Galko
%
% CHANGE HISTORY:
% ==============
% Addition of the \incposition macro and the \captionbaselineskip
% parameter (controls linespacing in captions), and changes to stop using 
% \count0 through \count4. Small changes to text as well.         Jan.  6/92  
% -
% Additions to the explanatory text, correction of the \scaledfigure macro
%  (the provision for an external pictfile had been missing), correction to the
%  \scaledepsffigure macro, the addition of the missing definition of \@pictf,
%  addition of the ability to shift figures horizontally without bounding box
%  changes, changes to the \checknumber macro to allow EPSF bounding box 
%  values to be any real number [Illustrator 3.2 can produce this, although
%  Adobe's own documentation states that conforming EPSF 3.0 files have only
%  integer valued coordinates in the %%BoundingBox statement.]    Dec. 19/91
% -
% Changes to explanatory text, the addition of the three macros to handle 
%  epsf files more automatically (\epsffigure, \scaledepsfigure, and 
%  \stretchedepsffigure), and a modification in the computation of dimensions
%  with scaled objects was made so that the computation is almost absolutely
%  accurate (the error in computing scaled values before was between 0 and
%  .01524pt * [the scaling factor] which is almost always negligible on a 300dpi
%  printer where 1 pixel is about .24pt; thus this improvement is unlikely to be
%  noticed except in very delicate situations or when scale factors are
%  significantly larger than 15 [i.e., scaled by 15000]).         Sept.27/91
% -
% Corrected \hboxmax macro                                        Feb. 11/91
% -
% Updated to allow for the possibility of PICT file (the "\special pictfile"  
%   option added in Textures 1.3).                                Feb.  2/91 
% -
% Modified to add "\par" after $$ in scaledfigure and figure macros to stop 
%  the possibility of page breaks between a figure and its caption (an 
%  empty box with glue was formerly being added there).           Jan.  8/91 
% -
% Editorial changes clarifying things further																					Aug. 21/90 
% -
% The example macro was corrected ("i" in param #1 should have been "epsf") 
%   and added a \reposition figure placement command.             Aug. 20/90 
%
% This is a collection of macros which is intended to make the task of importing
% drawing into Textures documents easier. The main macro is the \figure macro.
% It will insert a named graphic object in the typeset document and centering
% it on the full current line according to the object dimensions given to the
% macro (or determined from the BoundingBox comments in the epsf file in the
% case of the \epsffigure and \scaledepsffigure macros). To properly understand
% how this works, you need to understand that on the Macintosh there are
% different ways in which graphic objects are stored.  These storage methods
% are discussed briefly below.
%
% PICT and EPSF:
% =============
% When an object is drawn on a Macintosh screen, the Macintosh is using a
% description of the object given in its own graphic language called
% Quickdraw. When you want to print the picture, the printer driver may take
% this Quickdraw description and convert it to instructions which the printer
% needs to produce (hopefully) the same result.  Quickdraw, however, has certain 
% limitations on its graphic powers arising from its being tailored to the
% limited resolution of the 72 dpi Mac screen.  As a result, when the printing of
% a graphic object rendition occurs in the manner just described, the quality of
% the printed image suffers with respect to the drawer's original intention (not
% the Mac screen) even if the printer is inherently capable of greater resolution.
% Many printers (such as the LaserWriter printers) are capable of much better
% resolution than the Macintosh screen provides and often have other graphic
% languages built-in to them that are more powerful than Quickdraw.  A
% particularly widely used class of printers are those which use PostScript to
% describe everything to be printed.  PostScript is a powerful graphic language
% developed by Adobe Systems Incorporated which has become an industry standard
% for page description.  It allows a graphic object to be described intrinsically
% without worrying much about the resolution of the printer. It is the printer
% and the PostScript interpreter on a particular printer which completes the
% task of building the raster image of the graphic object. There are PostScript
% printers available with a variety of resolutions from 300 dpi all the way to
% 1800 dpi (and perhaps higher).  The Apple LaserWriter II NT, and NTX printers
% are 300 dpi PostScript printers, while Apple's newest printers the LaserWriter
% IIf and IIg are said to effectively have a resolution of 600 dpi (they are
% not true 600 dpi printers however).  Besides providing flexibility and much
% better resolution, PostScript also provides special effects not available
% in Quickdraw (for example, Quickdraw is incapable of writing *directly* text
% at an angle).  Since there is no direct correspondence between PostScript
% and Quickdraw, programs which want to produce high quality results on
% PostScript printers must effectively produce two descriptions of a drawing
% in the end: a Quickdraw description and a PostScript description (actually,
% what some programs do is to generate their own special description of
% graphical objects which they can then translate into Quickdraw [in some
% rough form] and PostScript).
%
% In the Macintosh world their are a few common forms that are used for
% defining or storing pictures. When a Quickdraw description of a graphic object
% is stored, it is stored in "PICT format", either as a PICT file or as a
% PICT resource in another type of file (resources are like small subfiles
% stored in the resource fork of a Macintosh file [every Macintosh file is
% actually two files which are described as the two forks of the file: a data
% fork and a resource fork]). (There is actually a few variants of the PICT
% format, but thats a minor detail.)  Since every application can draw a graphic
% object on the screen, it can usually deal with PICT descriptions; Textures is no
% exception and can import these PICT defined objects and place them in resources
% in the resource fork of the file holding your TeX source and the typeset
% results file, or it can read them from an external PICT file (as can be
% produced by MacDraw). When placed as resources in your document, these can be
% viewed in the pictures window in Textures. To bring in a drawing into the
% pictures window you simply use the cut and paste operations either with the
% clipboard, the scrapbook, or if you are running Multifinder (or System
% 7) seemingly directly between applications. (The source of your TeX file is
% stored in the data fork of a Textures file, with the DVI of the typeset
% result stored in the resource fork [one resource for the DVI output for each
% separate page] along with the PICT resources defining pictures.) 
% Unfortunately since such graphic object descriptions can commonly run in size
% to 50 kilobytes or more, if a document has many such drawings in it, it can
% become very large in size and therefore unwieldy.
% 
% The PICT format was defined well before PostScript appeared on the scene,
% and allowed only Quickdraw commands to be part of the file.  For the reasons
% mentioned above, it was felt desirable to allow PostScript descriptions of
% of objects to be included in these files as well. This was accomplished by
% making use of the comment command in Quickdraw: if a program wants to make use
% of PostScript for printing, it simply includes all the necessary commands as
% comments in the PICT description (which makes the PICT file or resource more
% than twice as long).  Such PICT files have two complete descriptions stored
% along with a significant amount of overhead, and any Mac application reading
% them needs to skip over a lot of material. To make matters more efficient,
% another format was developed to store the Quickdraw and PostScript
% descriptions known as Encapsulated PostScript Format (EPSF).  In this format,
% the two graphic object descriptions are stored as separate parts of a Macintosh
% file, with the Quickdraw description stored in the resource fork of the file, 
% and the PostScript description stored in the data fork. Most drawing programs
% either use EPSF to store objects (e.g., Adobe Illustrator) or are capable of
% generating EPSF files for the drawings they produce (e.g., Freehand and
% Cricket Draw).  Textures is able to incorporate any EPSF specified object into
% a document. An EPSF document does not become part of a Textures file, which 
% keeps the Textures document size down to reasonable size.  EPSF files have an
% additional advantage which is that they are simply text files (albeit
% possibly with some resources in the data fork) and usually contain explicitly
% some information that is useful to properly handle the image in other documents. 
% 
% Each graphic object file format, whether Quickdraw or PostScript, contains
% the specification of a bounding box for the object---an imaginary rectangular
% box with sides parallel to the coordinate axes which in theory should just
% surround the object, but in practice is often made a little bit larger than just
% this.  Textures uses the relation between the lower left hand corner of this
% bounding box and the rest of the object to control placing of the object.  When
% a PICT image is copied in the picture window, the dimensions of the object that
% Textures reports is based only on this bounding box. If you need to, you can
% read the data fork of an EPSF file to find the bounding box location in
% this case, but this is often unnecessary.  All EPSF files must follow a
% particular format established by Adobe (there are actually a few different
% versions of this format, but for our purposes the differences are not
% material; the latest version is version 3.0 which is documented in Appendix H
% of the PostScript Language Reference Manual, 2nd ed., Addison-Wesley, 1990).
% These files besides carrying the PostScript commands to draw the picture, 
% have comment lines which provide various pieces of information about the 
% illustration.  The bounding box is provided as one of the first few lines in
% a statement of the form
%              %%BoundingBox llx lly urx ury
% where (llx,lly) are the coordinates of the lower left hand corner of the
% bounding box and (urx,ury) are the coordinates of the upper right corner.
% Units are in pixels (72 pixels/inch) or what is referred to as 'big points'
% in TeX.
%
% When it was indicated above that an EPSF file had a QuickDraw version of the
% figure in it resource fork, it was not entirely true.  The EPSF format does
% not *require* that a QuickDraw version be included and some programs like
% Illustrator allow you to choose whether or not to place a QuickDraw version
% in the EPSF file (and what version of such a QuickDraw 'preview' to use if
% this is to be included).  If no QuickDraw version is included in the EPSF
% file, Textures will not draw the figure in the preview window---you will only
% see the figure when the document is printed on a PostScript printer.
% 
% Here is an example of the first few lines from the data fork [the PostScript
% part] of an EPSF file 'Test Figure' generated by Adobe Illustrator 3.2 (the
% lines begin with the % character after the blanks):
%
%        %!PS-Adobe-3.0 
%        %%Creator: Adobe Illustrator(TM) 3.2
%        %%For: (Peter Galko) (Department of Electrical Engineering)
%        %%Title: (Test Figure)
%        %%CreationDate: (12/13/91) (5:26 PM)
%        %%BoundingBox: 137 587 492 686
%        %%DocumentProcessColors:
%        %%DocumentNeededResources: procset Adobe_packedarray 2.0 0
%        %%+ procset Adobe_cmykcolor 1.1 0
%        %%+ procset Adobe_cshow 1.1 0
%        %%+ procset Adobe_customcolor 1.0 0
%        %%+ procset Adobe_IllustratorA_AI3 1.0 1
%        %AI3_ColorUsage: Black&White
%        %AI3_TemplateBox: 306 396 306 396
%        %AI3_TileBox: 30 31 582 761
%        %AI3_DocumentPreview: None
%        %%EndComments
%        %%BeginProlog
%        %%IncludeResource: procset Adobe_packedarray 2.0 0
%        ...
%
% In this example, we see that the drawing has its lower left hand coordinates
% at coordinates (137,587) and its upper right corner at (492,686).
% The very first line indicates that it is an EPSF file conforming to the 3.0
% specification. We also see lines here that state that the drawing is only in
% black and white, there is no preview (a Quickdraw version of the figure) stored
% in the file [which means that Textures would not be able to draw this figure in
% its preview window; we could have added the Quickdraw version when the file was
% save by Illustrator---it just wasn't done in this case].
%
% A good practice to follow in making drawings is to finish by drawing a box
% around your object, and then setting the line thickness of the box to zero
% and the line to be transparent to make the outlining box invisible (or in some
% way leaving the box unstroked and unfilled); this box should then very nearly
% correspond to the bounding box the application generating the figure should
% specify.  Most graphic applications will specify the bounding box to be one to
% two points larger than the drawn outline.  Often this is unimportant, but if
% necessary can be found by reading the EPSF file using Textures itself or most
% text file editors.  If the figure were drawn so that the lower left hand corner
% of the drawn outline box was placed at the origin (something you can easily do
% with Adobe Illustrator after the figure was already drawn), then the position of
% the lower left-hand corner relative to the bounding box specified lower left-hand
% corner is (-llx,-lly).  The bounding box specified in a file will be reported
% in the Textures log file if you simply add the statement \epsfverbosetrue to the
% the TeX file.
%
% 
% Specifying PICT and EPSF objects
% ================================
% To 'input' a drawing into a typeset document, you make use of the \special
% command in TeX. To import a PICT picture stored in the resource fork of the
% document you simply issue the command
%       \special picture 'name'
% where 'name' is the name of the PICT object (no quotes appear in the command)
% that you gave it when the object was copied into the pictures window. If the
% PICT picture is stored as a separate resource, you simply issue the command
%       \special pictfile 'name'
% Similarly, you include an EPSF file by issuing the command
%       \special illustration 'name'
% where 'name' is replaced by the name (no quotes appear in the command unless
% they are part of the file name [and colons have special significance in file
% names which disallows them as part of a low level file name]) of the EPSF file
% (which should be placed in the same folder as the Textures document;
% otherwise you will have to specify the full directory name including the
% volume name and hierarchy of folders). The lower left point of the bounding
% box of the graphic object is then placed at the current point and the object
% is drawn. Thus the current point must first be moved so that the drawing will
% not overlap onto other output and otherwise be properly positioned. Some
% macros which take care of the positioning and importation of PICT and EPSF
% objects are given below. The macros center drawings on the current line
% according to picture dimensions explicitly given to the macro.  The dimensions
% of the bounding box of a graphic are not known to TeX, only to the printer
% driver and previewer. Thus you can in practice give other dimensions for the
% bounding box of the object if you want to shift the image on the page.  Doing
% so however will change the dimensions of the box that you may want drawn
% around the figure which may be undesireable.  You can shift the figure and
% encompasing box without changing the box size by specifying a value for the
% parameter \shiftleft just before a figure placement macro occurs.  For example,
% saying '\shiftleft=1cm' just before invoking a figure placement macro will make
% the figure shift to the left by one centimeter on the page.  In the case that
% \rlth=0pt [i.e., no outline of the box is to be provided], the same effect could
% have been had by increasing the indicated width of the figure by two
% centimeters.
%
% 
% Macro description and specification:
% ===================================
% 
% The Figure Placement Macros:
% ---------------------------
% 1. The \figure macro
% 2. The \scaledfigure macro
% 3. The \epsffigure macro
% 4. The \scaledepsffigue macro
% 5. The \stretchedepsfigure macro
%
% = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
% The \figure macro creates a box of a specified inside dimension and then
% puts the graphic object inside aligning the lower left inside corner with
% the lower left corner of the bounding box of the object. The thickness
% of the lines forming the box are given by the parameter \rlth, and setting 
% this dimension to zero (the default value) results in the suppression
% of the outlining box. The macro also allows further TeX material to be 
% typeset on top of the figure (see the text placement macros below).
%
% Macro \figure #1 #2 by #3 #4 #5 #6 #7
%   first argument:   a few letters indicating the type of graphic file
%                     format---either "epsf", "pict" (for a PICT resource), or
%                     "pictf" (for an external PICT file) is possible.
%   second argument:  the horizontal width of the picture (a number with units
%                     as in 1.23cm, 2.45in, 34.5pt, etc.)  
%   third argument:   the vertical height of the picture (a number with units
%                     as in 1.23cm, 2.45in, 34.5pt, etc.)  Specifying a zero
%                     dimension causes the figure to be suppressed.
%   fourth argument:  the name of the picture (resource or file).
%   fifth argument:   extra information which can add text on top of a picture
%                     (what appears here is TeXed relative to the lower left of
%                     the bounding box)
%   sixth argument:   the figure number (used as defined in the \fignostyle
%                     macro: if this parameter is blank, figure numbers are
%                     suppressed---otherwise the figure number is appended to
%                     "Fig.~" in bold, and followed by \quad in the caption).
%   seventh argument: the figure caption (if nothing is given, a caption is
%                     suppressed, even if a figure number is specified). The
%                     caption style is controlled by the \captionstyle macro, 
%                     which is set to produce a single centered line if the
%                     caption fits on one line, two lines centered one above
%                     the other if the caption has two lines, and otherwise
%                     produces a paragraph style caption. The caption width is
%                     controlled by the dimension \captionwidth, which can be
%                     specified before the call to this macro. At the end of
%                     each use of this macro, \captionwidth is reset to
%                     \normalcaptionsize (currently set to \hsize).  The intent
%                     of this is to allow the user to avoid wide captions under
%                     very narrow figures which can be unattractive. The line
%                     spacing used in a caption is controlled by the parameter
%                     \captionbaselineskip (the original value is 12pt
%                     correspondind to single spacing in the normal
%                     environment).
%
% = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
%
% The \scaledfigure macro is a variation on the \figure macro. It has the 
% identical function except that the dimensions and the like are scaled in
% size.
%
% Macro \scaledfigure #1 scaled #2 #3 by #4 #5 #6 #7 #8
%   first argument:   a few letters indicating the type of graphic file
%                     format---either "epsf", "pict" (for a PICT resource), or
%                     "pictf" (for an external PICT file) is possible.
%   second argument:  an integer giving the scale in TeX units
%                     (1000 = original size) 
%   third argument:   the horizontal width of the picture before scaling (a
%                     number with units as in 1.23cm, 2.45in, 34.5pt, etc.) 
%   fourth argument:  the verticle height of the picture before scaling (a  
%                     number with units as in 1.23cm, 2.45in, 34.5pt, etc.)
%   fifth argument:   the name of the picture (resource or file)
%   sixth argument:   extra information which can add text on top of a picture
%                     (what appears here is TeXed relative to the lower left of
%                     the bounding box). Dimensions used in the text placement
%                     macros below are scaled too.
%   seventh argument: the figure number (used as defined in the \fignostyle
%                     macro: if this parameter is blank, figure numbers are
%                     suppressed---otherwise the figure number is appended to
%                     "Fig.~" in bold, and followed by \quad in the caption).
%   eighth argument:  the figure caption (if nothing is given, a caption is
%                     suppressed, even if a figure number is specified). The
%                     caption style is controlled by the \captionstyle macro, 
%                     which is set to produce a single centered line if the
%                     caption fits on one line, two lines centered one above
%                     the other if the caption has two lines, and otherwise
%                     produces a paragraph style caption. The caption width is
%                     controlled by the dimension \captionwidth, which can be
%                     specified before the call to this macro. At the end of
%                     each use of this macro, \captionwidth is reset to
%                     \normalcaptionsize (currently set to \hsize). The line
%                     spacing used in a caption is controlled by the parameter
%                     \captionbaselineskip (the original value is 12pt
%                     correspondind to single spacing in the normal
%                     environment).
%
% = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
% = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
%
% Automatic EPSF Macros
% ---------------------
% The \epsffigure macro is a version of the \figure macro which is only for EPSF
% figures, and differs in that the figure dimensions are determined by Textures
% from the bounding box specification in the EPSF file.  Thus the macro call does
% not provide the figure dimensions.  In this and the following two macros, by
% issueing a \epsfverbosetrue command, the macros can be made to report the size
% of the bounding box for the EPSF files in the log file
%
% Macro \epsffigure #1 #2 #3 #4 
%   first argument:   the name of the picture (resource or file)
%   second argument:  extra information which can add text on top of a picture
%                     (what appears here is TeXed relative to the lower left of
%                     the bounding box). Dimensions used in the text placement
%                     macros below are scaled too.
%   third argument:   the figure number (used as defined in the \fignostyle
%                     macro: if this parameter is blank, figure numbers are
%                     suppressed---otherwise the figure number is appended to
%                     "Fig.~" in bold, and followed by \quad in the caption).
%   fourth argument:  the figure caption (if nothing is given, a caption is
%                     suppressed, even if a figure number is specified). The
%                     caption style is controlled by the \captionstyle macro, 
%                     which is set to produce a single centered line if the
%                     caption fits on one line, two lines centered one above
%                     the other if the caption has two lines, and otherwise
%                     produces a paragraph style caption. The caption width is
%                     controlled by the dimension \captionwidth, which can be
%                     specified before the call to this macro. At the end of
%                     each use of this macro, \captionwidth is reset to
%                     \normalcaptionsize (currently set to \hsize). The line
%                     spacing used in a caption is controlled by the parameter
%                     \captionbaselineskip (the original value is 12pt
%                     correspondind to single spacing in the normal
%                     environment).
%
% = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
%
% The \scaledepsffigure macro is a version of the \epsffigure macro which
% differs only in that the figure is scaled in size in the document.  Thus the
% macro call does not include the figure dimensions.
%
% Macro \scaledepsffigure scaled #1 #2 #3 #4 #5 
%   first argument:   an integer giving the scale in TeX units
%                     (1000 = original size) 
%   second argument:  the name of the picture (resource or file)
%   third argument:   extra information which can add text on top of a picture
%                     (what appears here is TeXed relative to the lower left of
%                     the bounding box). Dimensions used in the text placement
%                     macros below are scaled too.
%   fourth argument:  the figure number (used as defined in the \fignostyle
%                     macro: if this parameter is blank, figure numbers are
%                     suppressed---otherwise the figure number is appended to
%                     "Fig.~" in bold, and followed by \quad in the caption).
%   fifth argument:   the figure caption (if nothing is given, a caption is
%                     suppressed, even if a figure number is specified). The
%                     caption style is controlled by the \captionstyle macro, 
%                     which is set to produce a single centered line if the
%                     caption fits on one line, two lines centered one above
%                     the other if the caption has two lines, and otherwise
%                     produces a paragraph style caption. The caption width is
%                     controlled by the dimension \captionwidth, which can be
%                     specified before the call to this macro. At the end of
%                     each use of this macro, \captionwidth is reset to
%                     \normalcaptionsize (currently set to \hsize).   The line
%                     spacing used in a caption is controlled by the parameter
%                     \captionbaselineskip (the original value is 12pt
%                     correspondind to single spacing in the normal
%                     environment).
%
%
% = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
%
% The \stretchedepsffigure macro is a version of the \epsffigure macro which
% allows the figure to be scaled in different ways to fit a specified size. 
% This allows only the contents of the EPSF file to be stretched, not
% the overlayed text. These effects will appear only in the printed output,
% although if a figure box is displayed, on the Macintosh's screen it will be
% have the proper dimensions and have its lower left hand corner appear in the
% same location as does the final box on the page.  The macro allows the 
% specification of the final width of the bounding box of the scaled drawing or
% the final height of the scaled drawing and possibly both.  When only one
% final dimension is specified, the figure is scaled uniformly in both
% directions.  When both final sizes are specified, the figure is scaled
% independently in the two directions. 
%
% Macro \stretchedepsffigure #1 by #2 #3 #4 #5 #6 
%   first argument:   the desired final horizontal width of the picture (a number
%                     with units as in 1.23cm, 2.45in, 34.5pt, etc.)  If a zero
%                     is specified, then the final horizontal width is computed
%                     from uniformly scaling the figure to have a height
%                     specified by the second parameter.  If both parameters are
%                     zero, then the figure is suppressed (although a caption 
%                     will remain).
%   second argument:  the desired final vertical height of the picture (a number
%                     with units as in 1.23cm, 2.45in, 34.5pt, etc.)  If a zero
%                     is specified, then the final vertical height is computed
%                     from uniformly scaling the figure to have a width
%                     specified by the first parameter.  If both parameters are
%                     zero, then the figure is suppressed (although a caption 
%                     will remain).
%   third argument:   the name of the EPSF file.
%   fourth argument:  extra information which can add text on top of a picture
%                     (what appears here is TeXed relative to the lower left of
%                     the bounding box)
%   fifth argument:   the figure number (used as defined in the \fignostyle
%                     macro: if this parameter is blank, figure numbers are
%                     suppressed---otherwise the figure number is appended to
%                     "Fig.~" in bold, and followed by \quad in the caption).
%   sixth argument:   the figure caption (if nothing is given, a caption is
%                     suppressed, even if a figure number is specified). The
%                     caption style is controlled by the \captionstyle macro, 
%                     which is set to produce a single centered line if the
%                     caption fits on one line, two lines centered one above
%                     the other if the caption has two lines, and otherwise
%                     produces a paragraph style caption. The caption width is
%                     controlled by the dimension \captionwidth, which can be
%                     specified before the call to this macro. At the end of
%                     each use of this macro, \captionwidth is reset to
%                     \normalcaptionsize (currently set to \hsize).  The line
%                     spacing used in a caption is controlled by the parameter
%                     \captionbaselineskip (the original value is 12pt
%                     correspondind to single spacing in the normal
%                     environment).
%
%
% Macro Definitions
% ===============================================================================
%
\catcode`\@=11
\newskip\prefigureskip \newskip\prefigureskipshort
\newskip\postfigureskip \newskip\prefiglabel 
%
% \prefigureskip defines the space between the material before a figure and
%    the top of the figure itself when the figure is wide
% \prefigureskipshort defines the space between the material before a figure
%    and the top of the figure itself when the figure is narrow
\prefigureskip=10pt plus3pt minus2pt \prefigureskipshort=2pt plus3pt minus1pt
% all the glue below is used with any baselineskip glue suppressed
% \prefiglabel defines the glue between outlininging box and figure label
% \postfiglabel defines the glue between the figure caption and the material
%  following (from the bounding box to the following material when the figure
%  caption is supressed)
\prefiglabel=4pt \postfigureskip=16pt plus 2ptminus 2pt
%
\newdimen\rlth \newcount\lines \rlth=0pt \def\nothing{} \newdimen\figwidth 
\newcount\count@@ \newcount\cnt@ \newcount\cnt@@ \newcount\cnt@@@
\newdimen\captionwidth \newdimen\captionbaselineskip \captionbaselineskip=12pt
\newdimen\leftshift \leftshift=0pt
\newcount\scalefx \newcount\scalefy \scalefx=1000 \scalefy=1000
\newdimen\normalcaptionwidth \normalcaptionwidth=\hsize
\captionwidth=\normalcaptionwidth
\def\@epsf{epsf} \def\@pict{pict} \def\@pictf{pictf}
\newdimen\xoffset \newdimen\yoffset \xoffset=0pt \yoffset=0pt
%
\def\figure #1 #2 by #3 #4 #5 #6 #7{{\def\@ft{#1}
\global\scalefx=1000\global\scalefy=1000
$$
\abovedisplayskip=\prefigureskip \belowdisplayskip=0pt 
\lineskip=0pt \baselineskip=0pt \abovedisplayshortskip=\prefigureskipshort
\belowdisplayshortskip=0pt \postdisplaypenalty=10000 \predisplaypenalty=200
\dimen0=#3
\ifdim\dimen0 = 0pt\else 
  \vbox{\hmaxbox to \hsize{\vrule width\rlth
    \vbox to#3{\offinterlineskip\hrule width#2 height\rlth
      \vbox to 0pt{\hrule width#2 height 0pt\vskip#3
      \ifx \@ft\@pict\special{picture #4}
       \else\ifx \@ft\@epsf\special{illustration #4}
        \else\ifx \@ft\@pictf\special{pictfile #4}
         \else\message{Illegal use of figure macro. The first argument should be}
              \message{'pict' (for a PICT image stored in the Textures file),}
              \message{'pictf' (for a PICT image stored as a separate file), or}
              \message{'epsf' (for an EPSF image stored in a separate file from}
              \message{the Textures file).}\fi\fi\fi
      #5\vss}\vfill\hrule height \rlth
    }\vrule width \rlth\hskip 2\leftshift}\par}
\fi
$$\par
\xdef\figcaption{#7} \ifx\figcaption\nothing\else\captionstyle{#6}{#7}\fi
\vskip\postfigureskip} \nointerlineskip \xoffset=0pt \yoffset=0pt \leftshift=0pt}
%
\def\fignostyle#1{\xdef\figno{#1}\if\figno\nothing \else{\bf Fig.~#1.}\quad\fi}
\def\captionstyle#1#2{\vskip \prefiglabel \nointerlineskip
 {\hsize=\captionwidth \baselineskip=\captionbaselineskip
 \parfillskip=0pt plus 1fil \parindent=0.0pt \parskip=0pt
 \global\setbox1=\vtop{\hskip\parfillskip\fignostyle{#1}
                 #2\par\global\lines=\prevgraf}}
 \ifnum\lines=1\vtop{\centerline{\box1}}
 \else
  \ifnum\lines=2\vtop{\centerline{\hsize=\captionwidth
      \vtop{\leftskip=0pt plus 1fil \rightskip=0pt plus 1fil
      \parfillskip=0pt\ignorespaces {\noindent\fignostyle{#1}} #2\vskip 0pt}}}
  \else \vtop{\centerline{\hsize=\captionwidth
   \vtop{\leftskip=0.3in \hskip -0.3in\fignostyle{#1} #2\vskip 0pt}}}
  \fi
 \fi \captionwidth=\normalcaptionwidth}
%
\def\hmaxbox to #1#2{\setbox2 = \hbox{#2} 
 \ifdim \wd2>#1 \hbox to #1{\hss\box2\hss} \global\figwidth=#1
  \else \box2 \global\figwidth=\wd2 
  \fi}
%
%%
%
\def\scaledfigure #1 scaled #2 #3 by #4 #5 #6 #7 #8{{\def\@ft{#1}
\global\scalefx=#2\global\scalefy=#2
$$
\abovedisplayskip=\prefigureskip \belowdisplayskip=0pt
\lineskip=0pt \baselineskip=0pt \abovedisplayshortskip=\prefigureskipshort
\belowdisplayshortskip=0pt \postdisplaypenalty=10000 \predisplaypenalty=200
\dimen0=#3 \dimen1=#4 \divide\dimen0 by 1000 \divide\dimen1 by 1000
\multiply\dimen0 by #2 \multiply\dimen1 by #2
\vbox{\hmaxbox to \hsize {\vrule width\rlth
  \vbox to\dimen1{\offinterlineskip\hrule width\dimen0 height\rlth
    \vbox to 0pt{\hrule width\dimen0 height 0pt\vskip\dimen1
    \ifx \@ft\@pict \special{picture #5 scaled #2}
     \else\ifx \@ft\@epsf \special{illustration #5 scaled #2}
      \else\ifx \@ft\@pictf\special{pictfile #5}
       \else\message{Illegal use of figure macro. The first argument should be}
            \message{'pict' (for a PICT image stored in the Textures file),}
            \message{'pictf' (for a PICT image stored as a separate file), or}
            \message{'epsf' (for an EPSF image stored in a separate file from}
            \message{the Textures file).}\fi\fi\fi
    #6\vss}\vfill\hrule height \rlth
  }\vrule width \rlth\hskip 2\leftshift}\par}
$$\par
\xdef\figcaption{#8} \ifx \figcaption\nothing\else\captionstyle{#7}{#8}\fi
\vskip\postfigureskip}
\nointerlineskip \xoffset=0pt \yoffset=0pt \leftshift=0pt}
%
%%
%
\def\epsffigure #1 #2 #3 #4{\epsfgetbb{#1}
    \ifepsfbbfound
        \ifepsfbbNAN
            \figure epsf 0pt by 0pt {#1} {#2} {#3} {#4}
        \else 
            \figure epsf {\the\epsfwidth} by {\the\epsfheight} {#1} {#2} {#3} {#4}
        \fi
    \else
        \figure epsf 0pt by 0pt {#1} {#2} {#3} {#4}
    \fi}

\def\scaledepsffigure scaled #1 #2 #3 #4 #5{\epsfgetbb{#2}
    \ifepsfbbfound
        \ifepsfbbNAN
            \figure epsf 0pt by 0pt {#2} {#3} {#4} {#5}
        \else
            \scaledfigure epsf scaled #1 {\the\epsfwidth} by {\the\epsfheight} {#2} 
                {#3} {#4} {#5}\fi
    \else
        \figure epsf 0pt by 0pt {#2} {#3} {#4} {#5}
    \fi}
%
%  If you want TeX to report the size of the figure (as a message
%   on your terminal when it processes each figure), say `\epsfverbosetrue'.
%
\newread\epsffilein      % file to \read
\newdimen\epsfwidth      % figure width
\newdimen\epsfheight     % figure height
\newif\ifepsffilereadon  % continue looking for the bounding box?
\newif\ifepsfbbfound     % bounding box comment found
\newif\ifepsfbbNAN       % bounding box is not specified
\newif\ifepsfverbose     % report what you're making?
{\catcode`\%=12 \global\def\pcnt{%}}
%
\def\epsfgetbb#1{%
%
%   The first thing we need to do is to open the
%   PostScript file, if possible.
%
    \openin\epsffilein=#1
    \ifeof\epsffilein\errmessage{I couldn't open the file #1.  I am ignoring the figure}
    \else
%
%   Okay, we got it. Now we'll scan lines until we find one that doesn't
%   start with %. We're looking for the bounding box comment.
%
      {\epsffilereadontrue \chardef\other=12
       \def\do##1{\catcode`##1=\other}\dospecials \catcode`\ =10
       \loop
           \read\epsffilein to \epsffileline
           \ifeof\epsffilein\epsffilereadonfalse
           \else
%
%   We check to see if the first character is a % sign;
%   if not, we stop reading (unless the line was entirely blank);
%   if so, we look further and stop only if the line begins with
%   `%%BoundingBox:'.
%
               \expandafter\epsfaux\epsffileline:. \\%
           \fi
           \ifepsffilereadon\repeat
       \ifepsfverbose
           \ifepsfbbfound
              \immediate\write16{The bounding box comment in the file "#1" is:"}
              \immediate\write16{\space\space\space"\pcnt\pcnt BoundingBox \epsfllx\space%
                       \epsflly\space\epsfurx\space\epsfury"}
           \else
              \immediate\write16{No bounding box comment found in "#1".  The figure is ignored}
           \fi
       \else\fi
       \ifepsfbbNAN
           \immediate\write16{The bounding box values in "#1" are unknown.  The figure is ignored.}\fi
       }
       \closein\epsffilein
    \fi}%
%
%   We still need to define the tricky \epsfaux macro. This requires
%   a couple of magic constants for comparison purposes.
%
{\catcode`\%=12 \global\let\epsfpercent=%\global\def\epsfbblit{%BoundingBox}}%
%
%   So we're ready to check for `%BoundingBox:' and to grab the
%   values if they are found.
%
\long\def\epsfaux#1#2:#3\\{
   \ifx#1\epsfpercent
       \def\testit{#2}
       \ifx\testit\epsfbblit
           \epsffilereadonfalse
           \global\epsfbbfoundtrue
           \epsfgrab #3 . . . \\%
       \else\fi
   \else
       \ifx#1\par                    % stop reading the file if a noncomment
       \else\epsffilereadonfalse\fi  % nonblank line is found in the file
   \fi}%
%
%   Here we grab the values and stuff them in the appropriate definitions.
%
\def\epsfgrab #1 #2 #3 #4 #5\\{%
   \global\def\epsfllx{#1}
   \ifx\epsfllx\empty
       \epsfgrab #2 #3 #4 #5 .\\
   \else
       \global\def\epsflly{#2}
       \global\def\epsfurx{#3}
       \global\def\epsfury{#4}
       \epsfbbNANfalse
       \checkifnumber{#1}\checkifnumber{#2}\checkifnumber{#3}\checkifnumber{#4}
       \ifepsfbbNAN
       \else
          {\epsfwidth=#3 bp\dimen0=#1 bp\global\advance\epsfwidth by -\dimen0
           \epsfheight=#4 bp\dimen0=#2 bp\global\advance\epsfheight by -\dimen0}
       \fi
   \fi}%
%
% The macros below will check if a string is a real number or not.  Spaces in the
% string are ignored entirely.  Thus "1 1" is a number, as is "+5", "-3.0",
% but not "++6", nor "1.2.0".  When a nonnumber is encountered, the command \epsfbbNANtrue
% is executed.  
%
\newif\ifstartnumber \newif\ifnodecimalpt 
\def\checkifnumber#1{\count@=0 \startnumbertrue\nodecimalpttrue\checknumber#1\end
    \ifnum\count@=0 \global\epsfbbNANtrue\else\fi}
\def\checknumber#1{
   \ifx#1\end\let\next=\relax
   \else
       \let\next=\checknumber
       \advance\count@ by 1                          % count the number of digits
       \count@@=`#1 
       \ifepsfbbNAN
       \else
           \ifnum\count@@ > 47                        % ASCII for digits is 48 -- 57
               \ifnum\count@@ < 58 \startnumberfalse
               \else \global\epsfbbNANtrue\fi
           \else
               \if#1.                                % check for a decimal point possibility
                   \startnumberfalse
                   \advance\count@ by -1
                   \ifnodecimalpt
                       \nodecimalptfalse
                   \else
                       \global\epsfbbNANtrue
                   \fi
               \else
                   \ifstartnumber                    % check for a leading sign
                       \if#1+
                           \startnumberfalse
                           \advance\count@ by -1
                       \else
                           \if#1-
                               \startnumberfalse
                               \advance\count@ by -1
                           \else
                               \global\epsfbbNANtrue
                           \fi
                       \fi
                   \else
                       \global\epsfbbNANtrue
                   \fi
               \fi
           \fi
       \fi
   \fi
   \next}
%
%
%
% The Text Placement Macros
% -------------------------
% A common problem one encounters in drawing objects relates to drawing in text.
% This is especially true in adding mathematics to a figure, or when one wants 
% to label a figure's elements using the CM fonts which are only available in
% TeX (except for the CM fonts rendered in Postscript form which can be
% accessed just as any other Macintosh font). To accomplish this, the following
% macros may be used to position material relative to a reference point which is 
% initially at the lower left hand corner of the the bounding box of the
% drawing. You simply specify to the appropriate macro how far to move (up and to
% the right are positive directions) and how to position text about the "end"
% location (either left, centered, or right justified horizontally, and with the
% baseline, textaxis (defined by considering the x-height of the current font) 
% or mathaxis at the end point, or with vertical top or bottom justification or
% centering). The text can also be rotated about the end point, although this is
% done by going behind Texture's back by sending unexpected PostScript stuff to
% the LaserWriter to acheive the effect. As a result, rotation thus works only
% on PostScript printers.
%
% Macro \position #1 #2 #3 by #4 #5 #6
%   first argument:  one of the words "left", "center", or "right" to
%                    indicate how the material of #6 is to be centered in the 
%                    horizontal ("left" means that the material is left
%                    justified where the left vertical edge of the 
%                    material is at the end point; "right" and
%                    "center" have similar corresponding meanings.)
%   second argument: one of the words "top", "center", "bottom", "baseline",
%                    "mathaxis", or "textaxis" to indicate how the material is 
%                    to be positioned vertically. "top" means that the top of
%                    the box enclosing the material of #6 is placed at the level
%                    of the end point, with "bottom" and "center" having
%                    similar corresponding meanings. "mathaxis" means that the
%                    normal position of the mathaxis of material specified 
%                    by \fontdimen22 of \textfont2 is placed at the level
%                    of the displaced point; "textaxis" means that the
%                    material is placed so that the midpoint of a letter "x"
%                    from \texfont0 would be at the level of the displaced
%                    point. Anything else (including "baseline") will have
%                    the baseline positioned at the level of the displaced
%                    point.
%   third argument:  the horizontal displacement (a number with units as in
%                    1.23cm, 2.45in, 34.5pt, etc.) from the reference point
%                    to the end point for the material to be added. The
%                    actual displacement will be this value scaled by the
%                    scale factor in \scaledfigure or \scaledepsffigure or 
%                    the effective horizontal scalefactor in
%                    \stretchedepsffigure if any of these macros are used.
%   fourth argument: the verticle displacement (a number with units as in
%                    1.23cm, 2.45in, 34.5pt, etc.) from the reference point
%                    to the end point for the material to be added. The
%                    actual displacement will be this value scaled by the
%                    scale factor in \scaledfigure or \scaledepsffigure or 
%                    the effective horizontal scalefactor in
%                    \stretchedepsffigure if any of these macros are used.
%   fifth argument:  the rotation in degrees counter-clockwise of the material
%                    of #6 about the displaced point to be applied (the 
%                    rotation does not appear in the preview).
%   sixth argument:  the text to be overlayed on the picture.
%
%
% The \reposition macro simply moves the reference point so that if the lower
% left hand corner of the bounding box isn't where it was thought to be, the
% reference point can in fact be moved to the position desired. The bounding
% box of a picture is specified by the program that generates the drawing, and
% is not always in predictable locations, hence the need for this macro. For
% example, if you draw a simple rectangular box in Adobe Illustrator, and
% perhaps just paint the box insides or even leave the box unpainted,
% Illustrator does not specify the coordinates of the box corners as the
% bounding box, but rather seems to indicate the bounding box is a slightly
% larger box encompasing the drawn box. This is a small difference which can
% be noticeable in some situations (the location of the bounding box can be
% found for an EPSF file by reading the comments in header part of the EPSF
% file or by specifying \epsfverbosetrue before using the \epsffigure macro
% and reading the TeX log file produced by Textures).
%
% Macro \reposition #1 by #2
%   first argument:  the horizontal displacement (a number with units as in
%                    1.23cm, 2.45in, 34.5pt, etc.) from the lower left hand 
%                    corner of the bounding box to where the reference point is
%                    to be positioned. The final position will be this value
%                    scaled by the scale factor in \scaledfigure if this macro
%                    is being used.
%   forth argument:  the verticle displacement (a number with units as in
%                    1.23cm, 2.45in, 34.5pt, etc.) from the lower left hand 
%                    corner of the bounding box to where the reference point is
%                    to be positioned. The final position will be this value
%                    scaled by the scale factor in \scaledfigure if this macro
%                    is being used.
%
% The \incposition macro is the same as \reposition, only its effects are 
% relative to the last position of the reference point and not to the lower 
% left corner of the original bounding box.  This can be particularly useful
% in figures that are actually composed of subfigures.
%
% Macro \incposition #1 by #2
%   first argument:  the horizontal displacement (a number with units as in
%                    1.23cm, 2.45in, 34.5pt, etc.) from the current position 
%                    of the reference point to where the reference point is 
%                    to be positioned. The final position of the reference
%                    will be the current position of the reference point 
%                    shifted by this value scaled by the scale factor in 
%                    \scaledfigure.                    
%   forth argument:  the verticle displacement (a number with units as in
%                    1.23cm, 2.45in, 34.5pt, etc.) from the current position 
%                    of the reference point to where the reference point is 
%                    to be positioned. The final position of the reference
%                    will be the current position of the reference point 
%                    shifted by this value scaled by the scale factor in 
%                    \scaledfigure.
%               
% AN EXAMPLE
% ==========
% An example of a figure in EPSF file being imported with text added using the 
% macros defined here. The figure is stored in an EPSF file with name
% "TestFigure" and has the axes labeled with TeX, and other comments added. The
% figure is scaled up by 10% from the version in the EPSF file. A simple caption
% is added.  The figure was generated using Illustrator 3.2.
%
% \scaledfigure epsf scaled 1100 13.0cm by 5.25cm TestFigure {
%  \reposition 1bp by 1bp %the bounding box is off by this much
%  \position right baseline 1.9cm by 3.5cm 0
%  {$\matrix{\hbox{generated}\cr\hbox{number}\cr (r_n)\cr}$}
%  \position left baseline 5.5cm by 0.25cm 0 {\hbox{seed \ \ $(r_{n-1})$}}
%  \position right textaxis 1.90cm by 4.50cm 0 {$N$}
%  \position center top 9.00cm by 0.4cm 0 {$N$}
%  \position center top 2.00cm by 0.4cm 0 {$0$}
%  \position left center 9.6cm by 3.5cm 0 {$\matrix{\hbox{($N$ is typically
%   the}\hfill\cr \hbox{maximum value}\hfill\cr
%   \hbox{representable in}\hfill\cr
%   \hbox{the computer)}\hfill\cr}$}} 1 {The Multiplicative Congruential Method}
%
\def\@c{center} \def\@r{right} \def\@l{left} \def\@t{top} \def\@b{bottom}
\def\@a{mathaxis} \def\@x{textaxis} \def\@zero{0}
%
\def\position #1 #2 #3 by #4 #5 #6{{
% the next few lines of the macro are some contortions performed to get TeX
% to scale the dimensions given in #3 and #4 accurately given that there is
% a limit on the size of dimensions of 2**30 sp and only integer arithmetic 
% available. (This is based on the fact that all dimension arithmetic is
% done in terms of values specified in small points, and the integer 
% division is truncated, not rounded.)  The result is the correctly rounded
% scaled value.
\dimen0=#3 \dimen3=\dimen0 \divide\dimen0 by 1000 \dimen2=\dimen0
 \multiply\dimen0 by \scalefx \multiply\dimen2 by -1000 \advance\dimen2 by \dimen3
 \multiply\dimen2 by \scalefx 
 \ifdim\dimen2 > 0pt \advance\dimen2 by 500sp \else\advance\dimen2 by -500sp\fi
 \divide\dimen2 by 1000 \advance\dimen0 by \dimen2 
\dimen1=#4 \dimen3=\dimen1 \divide\dimen1 by 1000 \dimen2=\dimen1
 \multiply\dimen1 by \scalefy \multiply\dimen2 by -1000 \advance\dimen2 by \dimen3
 \multiply\dimen2 by \scalefy 
 \ifdim\dimen2 > 0pt \advance\dimen2 by 500sp \else\advance\dimen2 by -500sp\fi
 \divide\dimen2 by 1000 \advance\dimen1 by \dimen2
\def\arga{#1}\def\argb{#2} \def\angle{#5}
\ifx \argb\@a \setbox0=\hbox{\lower\the\fontdimen22\textfont2\hbox{#6}}
 \else\ifx \argb\@c \setbox0=\hbox{\lower \the\fontdimen22\textfont2 
                                    \hbox{$\vcenter{\hbox{#6}}$}}
  \else\ifx \argb\@t \setbox0=\hbox{\vtop{\kern 0pt\hbox{#6}}}
   \else\ifx \argb\@b \setbox0=\hbox{\vbox{\hbox{#6}\kern 0pt}}
    \else\ifx \argb\@x \setbox0=\hbox{\lower 0.5ex\hbox{#6}}
   \else\setbox0=\hbox{#6} \fi\fi\fi\fi\fi
\setbox1=\hbox to 0pt{\ifx\arga\@l\else\hss\fi \box0
\ifx \arga\@r\else\hss\fi} \dp1=0pt 
\vbox to 0pt{\vss\hbox to 0pt{\kern\xoffset\kern \dimen0
     \ifx\zero\angle\box1\else{\rotate #5 \box1}\fi\hss}
     \vskip\yoffset\vskip \dimen1}
\nointerlineskip}}
%
% The macro that does the rotation is due to Charles Karney:
%%
%% Rotation of TeX output with Textures (and maybe? other PostScript drivers)
%%
%% Written by
%%   Charles Karney
%%   Plasma Physics Laboratory   Phone:   +1 609 243 2607
%%   Princeton University        MFEnet:  Karney@PPC.MFEnet
%%   PO Box 451                  ARPAnet: Karney%%PPC.MFEnet@NMFECC.ARPA
%%   Princeton, NJ 08543-0451    Bitnet:  Karney%%PPC.MFEnet@ANLVMS.Bitnet
%%
%% The following assumptions are made about the PostScript that TeXtures
%% generates:
%% (1) A single transform is used for all TeXtures output.
%% (2) The PostScript \special is bracketed by gsave ... grestore.
%% (3) Immediately after the gsave, the coordinate system is translated so the
%%     origin is at the current point; and the y axis is flipped.
%% (4) TeXtures doesn't leave anything on the stack for long periods. (This
%%     simplifies restoring the default coordinate system.)
%%
%% Usage:
%%   abc {\rotate 90 def} ghi
%% On a non-postscript printer this will print the same as ``abc def ghi''.
%% With TeXtures, the ``abc'' and ``ghi'' will appear on the page in the
%% same place as before, however the ``def'' is bodily rotated counter-
%% clockwise by 90 degrees. The rotation is about the bottom left corner of
%% the ``d''. The braces serve to delimit the extent of the rotated text.
%% The rotation angle is specified as an integer number of degrees. It can
%% be negative. \rotate should always appear within a group (not at top-
%% level). Rotations can be stacked, e.g.,
%%   abc {\rotate 90 def \rotate 90 ghi} jkl
%% would print as
%%   ihg
%%      f
%%      e
%%      d
%%   abc         jlk
%% except that the letters ``def'' would be sideways, and ``ghi'' would be
%% upside down.
%
\def\rotate{\afterassignment\@rotate\count@}
\def\@rotate{\aftergroup\@unrotate
\special
{postscript
  0 0 transform                 % Get current location in device coordinates.
  grestore                      % Undoes TeXtures gsave.
  matrix currentmatrix          % Save current transform on stack for use
                                % by \@unrotate.
  3 1 roll                      % Put transform at back of current location.
  itransform                    % Current location in TeXtures coords
  dup 3 -1 roll                 % Duplicate the location; x y ==> x y x y
  dup 4 1 roll exch
  translate                     % Translate origin to current location
  1 -1 scale                    % Flip y coordinate
  \the\count@\space rotate      % Rotate by \count@
  1 -1 scale                    % Unflip y coordinate
  neg exch neg exch translate   % Translate origin back
  gsave}}                       % To match grestore
\def\@unrotate{\special
{postscript
  grestore                      % Undoes Textures gsave
  setmatrix                     % Set current transform to value saved on
                                % stack. (Hopefully, it's still there.)
  gsave}}                       % To match grestore
%
% Below is a similar macro which allows stretching and rotation of material.
% It stretches material by the amount by the ratio of its first two arguments
% in the x direction and by the ratio of the third and fourth in the y direction
% and then rotates the object counterclockwise by the fifth argument (in degrees).
% Textures will know nothing about the changes in the dimensions of material until
% the material prints (the screen display will not reflect the transformation).
% [Macro due to P. Galko]
\def\transformation #1 #2 #3 #4 #5 {\dimen0=#1 \cnt@=\dimen0 
  \dimen0=#2 \cnt@@=\dimen0 \dimen0=#3 \cnt@@@=\dimen0 
  \dimen0=#4 \count@@=\dimen0 \count@=#5 \@transf}
\def\@transf{\aftergroup\@untransf
\special
{postscript
  0 0 transform                 % Get current location in device coordinates.
  grestore                      % Undoes TeXtures gsave.
  matrix currentmatrix          % Save current transform on stack for use
                                % by \@unrotate.
  3 1 roll                      % Put transform at back of current location.
  itransform                    % Current location in Textures coords
  dup 3 -1 roll                 % Duplicate the location; x y ==> x y x y
  dup 4 1 roll exch
  translate                     % Translate origin to current location
  1 -1 scale                    % Flip y coordinate
  \the\count@ \space rotate     % Rotate by \count@
  \the\cnt@ \space 
  \the\cnt@@ \space div         % compute x scale factor (=#1/#2)
  \the\cnt@@@ \space 
  \the\count@@ \space div scale % compute y scale factor with flip (=#3/#4)
  1 -1 scale                    % Unflip y coordinate
  neg exch neg exch translate   % Translate origin back
  gsave}}                       % To match grestore
\def\@untransf{\special
{postscript
  grestore                      % Undoes Textures gsave
  setmatrix                     % Set current transform to value saved on
                                % stack. (Hopefully, it's still there.)
  gsave}}                       % To match grestore
%\catcode`\@=12
%
\def\reposition #1 by #2 {\xoffset=#1 \dimen0=\xoffset
  \divide\xoffset by 1000 \dimen1=\xoffset \multiply\xoffset by \scalefx 
  \multiply\dimen1 by -1000 \advance\dimen0 by \dimen1 \multiply\dimen0 by \scalefx
  \ifdim\dimen0>0sp\advance\dimen0 by 500sp \else\advance\dimen0 by -500sp\fi
  \divide\dimen0 by 1000 \advance\xoffset by \dimen0 
 \yoffset=#2 \dimen0=\yoffset
  \divide\yoffset by 1000 \dimen1=\yoffset \multiply\yoffset by \scalefy
  \multiply\dimen1 by -1000 \advance\dimen0 by \dimen1 \multiply\dimen0 by \scalefy
  \ifdim\dimen0>0sp\advance\dimen0 by 500sp \else\advance\dimen0 by -500sp\fi
  \divide\dimen0 by 1000 \advance\yoffset by \dimen0 }
%
% The next macro is the same as \reposition, only its effects are relative to
% the last position and not to the original bounding box lower left corner.
%
\def\incposition #1 by #2 {\dimen2=\xoffset \xoffset=#1 \dimen0=\xoffset
  \divide\xoffset by 1000 \dimen1=\xoffset \multiply\xoffset by \scalefx 
  \multiply\dimen1 by -1000 \advance\dimen0 by \dimen1 \multiply\dimen0 by \scalefx
  \ifdim\dimen0>0sp\advance\dimen0 by 500sp \else\advance\dimen0 by -500sp\fi
  \divide\dimen0 by 1000 \advance\xoffset by \dimen0\advance\xoffset by \dimen2
 \dimen2=\yoffset \yoffset=#2 \dimen0=\yoffset
  \divide\yoffset by 1000 \dimen1=\yoffset \multiply\yoffset by \scalefy
  \multiply\dimen1 by -1000 \advance\dimen0 by \dimen1 \multiply\dimen0 by \scalefy
  \ifdim\dimen0>0sp\advance\dimen0 by 500sp \else\advance\dimen0 by -500sp\fi
  \divide\dimen0 by 1000 \advance\yoffset by \dimen0\advance\yoffset by \dimen2}
%
%
\def\stretchedepsffigure #1 by #2 #3 #4 #5 #6{
{\epsfgetbb{#3}
% First a few contortions to accurately compute scale factors in integer mils
% (integer out of 1000).  It is assumed that no dimensions involved are larger
% than (2**30)/10 sp or about 1638.4pt = 22.67in = 57.6cm.  If dimensions exceed
% this limit, one *MAY* experience some overflow in arithmetic computations.
 \dimen0=#1 \multiply\dimen0 by 10 \dimen1=\dimen0 \divide\dimen0 by \epsfwidth
   \scalefx=\dimen0 \count@=\scalefx \multiply\scalefx by 100 
   \advance\dimen1 by -\count@\epsfwidth
   \dimen0=\dimen1 \multiply\dimen0 by 10 \dimen1=\dimen0
   \divide\dimen0 by \epsfwidth \count@=\dimen0 \advance\dimen1 by -\count@\epsfwidth
   \multiply\count@ by 10\advance\scalefx by \count@ \multiply\dimen1 by 10
   \advance\dimen1 by 0.5\epsfwidth \divide\dimen1 by \epsfwidth 
   \advance\scalefx by \dimen1
 \dimen0=#2 \multiply\dimen0 by 10 \dimen1=\dimen0 \divide\dimen0 by \epsfheight
   \scalefy=\dimen0 \count@=\scalefy \multiply\scalefy by 100 
   \advance\dimen1 by -\count@\epsfheight
   \dimen0=\dimen1 \multiply\dimen0 by 10 \dimen1=\dimen0
   \divide\dimen0 by \epsfheight \count@=\dimen0 \advance\dimen1 by -\count@\epsfheight
   \multiply\count@ by 10\advance\scalefy by \count@ \multiply\dimen1 by 10
   \advance\dimen1 by 0.5\epsfheight \divide\dimen1 by \epsfheight 
   \advance\scalefy by \dimen1
 \dimen0=#1 \dimen1=#2
 \ifdim\dimen0=0sp
     \ifdim\dimen1=0sp
         \scalefx=1000 \scalefy=1000 
     \else
         \dimen0=\epsfwidth \dimen2=\dimen0 \divide\dimen2 by 1000
         \advance\dimen0 by -1000\dimen2 \multiply\dimen0 by \scalefy
         \divide\dimen0 by 1000 \advance\dimen0 by \scalefy\dimen2
         \scalefx=\scalefy
     \fi
 \else
     \ifdim\dimen1=0sp
         \dimen1=\epsfheight \dimen2=\dimen1 \divide\dimen2 by 1000         
         \advance\dimen1 by -1000\dimen2 \multiply\dimen1 by \scalefx
         \divide\dimen1 by 1000 \advance\dimen1 by \scalefx\dimen2
         \scalefy=\scalefx
     \else\fi
 \fi
 $$
 \abovedisplayskip=\prefigureskip \belowdisplayskip=0pt 
 \lineskip=0pt \baselineskip=0pt \abovedisplayshortskip=\prefigureskipshort
 \belowdisplayshortskip=0pt \postdisplaypenalty=10000 \predisplaypenalty=200
 \ifdim\dimen0 = 0pt
 \else 
     \vbox{
         \hmaxbox to \hsize{
             \ifdim\rlth=0pt\else\vrule width\rlth\fi
             \vbox to\dimen1{
                 \offinterlineskip\ifdim\rlth=0pt\else\hrule width\dimen0 height\rlth\fi
                 \vbox to 0pt{\hrule width \dimen0 height 0pt\vskip\dimen1
                              {\transformation #1 {\the\epsfwidth} #2 {\the\epsfheight} 0
                               \special{illustration #3}}
                              #4\vss}
                 \vfill\ifdim\rlth=0pt\else\hrule height \rlth\fi
                 }\ignorespaces
             \ifdim\rlth=0pt\else\vrule width\rlth\fi\hskip 2\leftshift
             }\par
         }
 \fi
 $$\par
 \xdef\figcaption{#6} \ifx\figcaption\nothing\else\captionstyle{#5}{#6}\fi
 \vskip\postfigureskip
}\nointerlineskip \xoffset=0pt \yoffset=0pt \leftshift=0pt}

\catcode`\@=12
\rlth=0pt
